{extend name="main" /}

{block name="title_seo"}
<title>修改资料</title>
<meta name="keywords" charset="UTF-8" content="">
<meta name="description" content="">
{/block}

{block name="body"}
<div class="layui-container">
    <div class="layui-row layui-col-space30" style="margin-top: 80px;">
        <div class="layui-col-md3">
            {include file="user/nav" /}
        </div>
        <div class="layui-col-md9">
            <div class="layui-panel">
                <div class="layui-card-header">修改资料</div>
                <div class="layui-card-body">
                    <div class="layui-form">
                        <form action="{:request()->url()}" method="post" class="xn_ajax">
                            <div class="layui-form-item">
                                <label class="layui-form-label">头像</label>
                                <div class="layui-input-block">
                                    <p style="padding-bottom: 10px">
                                        <img src="{$user.avatar|default='/static/index/images/addimg.png'}"  style="width: 92px; height: 92px;" class="xn-upload-img">
                                        <input type="hidden" name="avatar" id="avatar" value="{$user.avatar}">
                                    </p>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">昵称</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="nickname" lay-verify="required" placeholder="昵称" autocomplete="off" class="layui-input" value="{$user.nickname}">
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <label class="layui-form-label">简介</label>
                                <div class="layui-input-block">
                                    <textarea class="layui-textarea" name="intro" placeholder="个人简介">{$user.intro}</textarea>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button type="submit" lay-submit class="layui-btn">修改</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{/block}

{block name="js"}
<script>
    layui.use(function(){
        var upload = layui.upload;
        var layer = layui.layer;
        var $ = layui.$;
        // 单图片上传
        var uploadInst = upload.render({
            elem: '.xn-upload-img',
            url: "{:url('user/uploadAvatar')}", // 实际使用时改成您自己的上传接口即可。
            done: function(res){
                if(res.code === 0){
                    return layer.msg('上传失败');
                }
                $('.xn-upload-img').attr('src', res.file); // 置空上传失败的状态
                $('#avatar').val(res.file);
            },
            error: function(){
                return layer.msg('上传失败');
            },
        });
    });
</script>
{/block}